﻿using System;
using System.IO;
using System.Net;
using System.Text;

namespace zhangmenren.Untils
{
    public class Http
    {
        public static string RequestPost(string url, string postData)
        {
            try
            {
                //发送请求的数据
                WebRequest myHttpWebRequest = WebRequest.Create(url);
                myHttpWebRequest.Method = "POST";
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] byte1 = encoding.GetBytes(postData);
                myHttpWebRequest.ContentType = "application/json";
                myHttpWebRequest.ContentLength = byte1.Length;
                Stream newStream = myHttpWebRequest.GetRequestStream();
                newStream.Write(byte1, 0, byte1.Length);
                newStream.Close();

                //发送成功后接收返回的XML信息
                HttpWebResponse response = (HttpWebResponse)myHttpWebRequest.GetResponse();
                string lcHtml = string.Empty;
                Encoding enc = Encoding.GetEncoding("UTF-8");
                Stream stream = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, enc);
                lcHtml = streamReader.ReadToEnd();
                return lcHtml;
            }
            catch (Exception e)
            {
                //LogHelper.LogWarn(e.Message);
                return "";
            }
        }
    }
}
